home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / Tool Chest / Games / Game Sample Code / SpriteWorld 1.0b3 / Examples / SpaceRocks / ShipSprite.c < prev    next >
Encoding:
Text File  |  1993-06-13  |  17.4 KB  |  654 lines  |  [TEXT/KAHL]

  1. ///--------------------------------------------------------------------------------------
  2. //    ShipSprite.c
  3. //
  4. //    Created: 6/18/92 at 2:29:31 PM
  5. //    By:        Tony Myles
  6. //
  7. //    Copyright: © 1992-93 Tony Myles, All rights reserved worldwide.
  8. ///--------------------------------------------------------------------------------------
  9.  
  10.  
  11. #ifndef _H_math
  12. #include <math.h>
  13. #endif
  14.  
  15. #ifndef __FIXMATH__
  16. #include <FixMath.h>
  17. #endif
  18.  
  19. #ifndef __SPRITEWORLD__
  20. #include <SpriteWorld.h>
  21. #endif
  22.  
  23. #ifndef __SPRITELAYER__
  24. #include <SpriteLayer.h>
  25. #endif
  26.  
  27. #ifndef __BLITPIXIE__
  28. #include <BlitPixie.h>
  29. #endif
  30.  
  31. #ifndef __GAMEUTILS__
  32. #include <GameUtils.h>
  33. #endif
  34.  
  35. #ifndef __SOUNDUTILS__
  36. #include <SoundUtils.h>
  37. #endif
  38.  
  39. #ifndef __DEBUGUTILS__
  40. #include <DebugUtils.h>
  41. #endif
  42.  
  43. #ifndef __SHIPSPRITE__
  44. #include "ShipSprite.h"
  45. #endif
  46.  
  47.  
  48. Boolean gShipSoundDone;
  49. RgnHandle gWorkRgn;
  50.  
  51.  
  52. ///--------------------------------------------------------------------------------------
  53. //        CreateShipSprite
  54. ///--------------------------------------------------------------------------------------
  55.  
  56. OSErr CreateShipSprite(
  57.     ShipSpritePtr* shipSpriteP)
  58. {
  59.     OSErr err;
  60.     ShipSpritePtr tempShipSpriteP;
  61.  
  62.     *shipSpriteP = NULL;
  63.  
  64.     tempShipSpriteP = (ShipSpritePtr)NewPtr(sizeof(ShipSpriteRec));
  65.  
  66.     if (tempShipSpriteP != NULL)
  67.     {
  68.             // create the ship sprite
  69.         err = SWCreateSpriteFromCIconResource((SpritePtr*)shipSpriteP, tempShipSpriteP,
  70.                                                             kShipFrameResID, kNumberOfShipFrames, kFatMask);
  71.     }
  72.     else
  73.     {
  74.         err = MemError();
  75.     }
  76.  
  77.     return err;
  78. }
  79.  
  80.  
  81. ///--------------------------------------------------------------------------------------
  82. //        DisposeShipSprite
  83. ///--------------------------------------------------------------------------------------
  84.  
  85. void DisposeShipSprite(
  86.     ShipSpritePtr shipSpriteP)
  87. {
  88.     if (shipSpriteP != NULL)
  89.     {
  90.         DisposeShipSounds(shipSpriteP);
  91.  
  92.         SWDisposeSprite((SpritePtr)shipSpriteP, true);
  93.     }
  94.  
  95.     DisposeRgn(gWorkRgn);
  96. }
  97.  
  98.  
  99. ///--------------------------------------------------------------------------------------
  100. //        InitShipSprite
  101. ///--------------------------------------------------------------------------------------
  102.  
  103. void InitShipSprite(
  104.     ShipSpritePtr shipSpriteP,
  105.     SpriteWorldPtr shipSpriteWorldP,
  106.     SpriteLayerPtr shipSpriteLayerP,
  107.     SpriteLayerPtr shotSpriteLayerP)
  108. {
  109.     gWorkRgn = NewRgn();
  110.     gShipSoundDone = true;
  111.  
  112.         // initialize some stuff
  113.     shipSpriteP->shipSndChannelP = NULL;
  114.     shipSpriteP->shipSpriteWorldP = shipSpriteWorldP;
  115.     shipSpriteP->shipSpriteLayerP = shipSpriteLayerP;
  116.     shipSpriteP->shotSpriteLayerP = shotSpriteLayerP;
  117.     shipSpriteP->shipWrapRect = shipSpriteWorldP->backFrameP->frameRect;
  118.  
  119.     shipSpriteP->shotCounter = 0;
  120.     shipSpriteP->shotTickDelay = 0;
  121.  
  122.     shipSpriteP->shipVelocity.h = 0;
  123.     shipSpriteP->shipVelocity.v = 0;
  124.     shipSpriteP->shipHorizLoc = 0;
  125.     shipSpriteP->shipVertLoc = 0;
  126.  
  127.     shipSpriteP->isAlive = false;
  128.  
  129.         // initialize the velocity table
  130.     CreateVelocityTable(shipSpriteP->angularVelocityTable, kNumberOfShipFrames, .751215935);
  131.     CreateVelocityTable(shipSpriteP->shotVelocityTable, kNumberOfShipFrames, 10.0);
  132.  
  133.         // add the ship to the layer
  134.     SWAddSprite(shipSpriteP->shipSpriteLayerP, (SpritePtr)shipSpriteP);
  135. }
  136.  
  137.  
  138. ///--------------------------------------------------------------------------------------
  139. //        CreateShipSounds
  140. ///--------------------------------------------------------------------------------------
  141.  
  142. OSErr CreateShipSounds(
  143.     ShipSpritePtr shipSpriteP)
  144. {
  145.     OSErr err;
  146.  
  147.         // initialize ship sound stuff
  148.     shipSpriteP->shipSndChannelP = NULL;
  149.     shipSpriteP->explosionSndH = NULL;
  150.     shipSpriteP->thrustSndH = NULL;
  151.     shipSpriteP->shotSndH = NULL;
  152.  
  153.         // create a new sound channel
  154.     err = SndNewChannel(&shipSpriteP->shipSndChannelP, sampledSynth,
  155.                                 initMono, (SndCallBackProcPtr)ShipSoundCallBack);
  156.  
  157.     if (err == noErr)
  158.     {
  159.         shipSpriteP->shipSndChannelP->userInfo = 0;
  160.         shipSpriteP->shipSndCmd.cmd = callBackCmd;
  161.         shipSpriteP->shipSndCmd.param2 = (long)&gShipSoundDone;
  162.  
  163.             // load the explosion sound
  164.         shipSpriteP->explosionSndH = GetSoundResource(kExplosionSoundResID, &err);
  165.     }
  166.  
  167.     if (err == noErr)
  168.     {
  169.             // load the thrust sound
  170.         shipSpriteP->thrustSndH = GetSoundResource(kThrustSoundResID, &err);
  171.     }
  172.  
  173.     if (err == noErr)
  174.     {
  175.             // load the shot sound
  176.         shipSpriteP->shotSndH = GetSoundResource(kShotSoundResID, &err);
  177.     }
  178.  
  179.     if (err != noErr)
  180.     {
  181.         DisposeShipSounds(shipSpriteP);
  182.     }
  183.  
  184.     return err;
  185. }
  186.  
  187.  
  188. ///--------------------------------------------------------------------------------------
  189. //        DisposeShipSounds
  190. ///--------------------------------------------------------------------------------------
  191.  
  192. void DisposeShipSounds(
  193.     ShipSpritePtr shipSpriteP)
  194. {
  195.     if (shipSpriteP->shipSndChannelP != NULL)
  196.     {
  197.         (void)SndDisposeChannel(shipSpriteP->shipSndChannelP, true);
  198.     }
  199. }
  200.  
  201.  
  202. ///--------------------------------------------------------------------------------------
  203. //        SetupShipSprite
  204. ///--------------------------------------------------------------------------------------
  205.  
  206. void SetupShipSprite(
  207.     ShipSpritePtr shipSpriteP)
  208. {
  209.     short shotSpriteNum;
  210.  
  211.     SWLockSprite((SpritePtr)shipSpriteP);
  212.  
  213.     SWSetSpriteMoveProc((SpritePtr)shipSpriteP, (MoveProcPtr)ShipMoveProc);
  214.     SWSetSpriteFrameProc((SpritePtr)shipSpriteP, (FrameProcPtr)ShipFrameProc);
  215.     SWSetSpriteCollideProc((SpritePtr)shipSpriteP, (CollideProcPtr)ShipCollideProc);
  216.     SWSetSpriteDrawProc((SpritePtr)shipSpriteP, BlitPixieMaskDrawProc);
  217.  
  218.     SWSetSpriteMoveTime((SpritePtr)shipSpriteP, -1);
  219.     SWSetSpriteMoveBounds((SpritePtr)shipSpriteP, &shipSpriteP->shipWrapRect);
  220.     SWSetSpriteFrameTime((SpritePtr)shipSpriteP, kShipFrameTime);
  221.     SWSetSpriteFrameAdvance((SpritePtr)shipSpriteP, 0);
  222.     SWSetSpriteLocation((SpritePtr)shipSpriteP,
  223.                                 shipSpriteP->shipWrapRect.right / 2,
  224.                                 shipSpriteP->shipWrapRect.bottom / 2);
  225.     SWSetSpriteVisible((SpritePtr)shipSpriteP, false);
  226.  
  227.     shipSpriteP->shipHorizLoc = ff(shipSpriteP->shipWrapRect.right / 2);
  228.     shipSpriteP->shipVertLoc = ff(shipSpriteP->shipWrapRect.bottom / 2);
  229.  
  230.     for (shotSpriteNum = 0; shotSpriteNum < kNumberOfShotSprites; shotSpriteNum++)
  231.     {
  232.         SWLockSprite((SpritePtr)shipSpriteP->shotSpriteArray[shotSpriteNum]);
  233.         SWSetSpriteDrawProc((SpritePtr)shipSpriteP->shotSpriteArray[shotSpriteNum], BlitPixieEraseProc);
  234.     }
  235. }
  236.  
  237.  
  238. ///--------------------------------------------------------------------------------------
  239. //        CreateShotSpriteArray
  240. ///--------------------------------------------------------------------------------------
  241.  
  242. OSErr CreateShotSpriteArray(
  243.     ShipSpritePtr shipSpriteP)
  244. {
  245.     OSErr err;
  246.     short shotSpriteNum = 0, numberOfShotSprites;
  247.     ShotSpritePtr* shotSpriteArray = shipSpriteP->shotSpriteArray;
  248.     ShotSpritePtr shotSpriteP, newShotSpriteP;
  249.  
  250.     err = SWCreateSpriteFromPictResource((SpritePtr*)&shotSpriteP,
  251.                                                     shipSpriteP->shotSpriteStorage,
  252.                                                     kShotFrameResID, 0, 1, kNoMask);
  253.  
  254.     if (err == noErr)
  255.     {
  256.         InitShotSprite(shipSpriteP, shotSpriteP);
  257.         shotSpriteArray[0] = shotSpriteP;
  258.  
  259.         for (shotSpriteNum = 1; shotSpriteNum < kNumberOfShotSprites; shotSpriteNum++)
  260.         {
  261.             err = SWCloneSprite((SpritePtr)shotSpriteP, (SpritePtr*)&newShotSpriteP,
  262.                                     shipSpriteP->shotSpriteStorage + shotSpriteNum);
  263.  
  264.             if (err == noErr)
  265.             {
  266.                 InitShotSprite(shipSpriteP, newShotSpriteP);
  267.                 shotSpriteArray[shotSpriteNum] = newShotSpriteP;
  268.             }
  269.             else
  270.             {
  271.                 break;
  272.             }
  273.         }
  274.     }
  275.  
  276.     if (err != noErr)
  277.     {
  278.             // dispose of any sprites that we managed to create
  279.         numberOfShotSprites = shotSpriteNum;
  280.  
  281.         for (shotSpriteNum = 0; shotSpriteNum < numberOfShotSprites; shotSpriteNum++)
  282.         {
  283.             SWDisposeSprite((SpritePtr)shotSpriteArray[shotSpriteNum], shotSpriteNum == 0);
  284.         }
  285.     }
  286.  
  287.     return err;
  288. }
  289.  
  290.  
  291. ///--------------------------------------------------------------------------------------
  292. //        InitShotSprite
  293. ///--------------------------------------------------------------------------------------
  294.  
  295. void InitShotSprite(
  296.     ShipSpritePtr shipSpriteP,
  297.     ShotSpritePtr shotSpriteP)
  298. {
  299.     SWSetSpriteMoveProc((SpritePtr)shotSpriteP, (MoveProcPtr)ShotMoveProc);
  300.     SWSetSpriteMoveTime((SpritePtr)shotSpriteP, kShotMoveTime);
  301.     SWSetSpriteMoveBounds((SpritePtr)shotSpriteP, &shipSpriteP->shipWrapRect);
  302.  
  303.     shotSpriteP->shotVelocity.h = 0L;
  304.     shotSpriteP->shotVelocity.v = 0L;
  305.     shotSpriteP->shotHorizLoc = 0L;
  306.     shotSpriteP->shotVertLoc = 0L;
  307.  
  308.     shotSpriteP->shipSpriteP = shipSpriteP;
  309.     shotSpriteP->shotLife = 0L;
  310. }
  311.  
  312.  
  313. ///--------------------------------------------------------------------------------------
  314. //        DisposeShotSprite
  315. ///--------------------------------------------------------------------------------------
  316.  
  317. void DisposeShotSprite(
  318.     ShipSpritePtr shipSpriteP)
  319. {
  320.     ShotSpritePtr shotSpriteP;
  321.     short shotSpriteNum;
  322.  
  323.     ReleaseResource(shipSpriteP->shotSndH);
  324.  
  325.     for (shotSpriteNum = 0; shotSpriteNum < kNumberOfShotSprites; shotSpriteNum++)
  326.     {
  327.             // since we allocated storage for the shot sprites ourself
  328.             // we must dispose of the sprites using this call
  329.         SWCloseSprite((SpritePtr)shipSpriteP->shotSpriteArray[shotSpriteNum], shotSpriteNum == 0);
  330.     }
  331. }
  332.  
  333.  
  334. ///--------------------------------------------------------------------------------------
  335. //        CreateVelocityTable
  336. ///--------------------------------------------------------------------------------------
  337.  
  338. void CreateVelocityTable(
  339.     Velocity* velocityTable,
  340.     short numAngles,
  341.     double radius)
  342. {
  343.     short i;
  344.     Fixed angle = 0;
  345.     Fixed angleIncrement = DblToFix((double)(kRadiansInCircle / numAngles));
  346.     Fixed fixedRadius = DblToFix(radius);
  347.  
  348.     for (i = 0; i < numAngles; i++)
  349.     {
  350.         velocityTable[i].h = FracMul(FracSin(angle), fixedRadius);
  351.         velocityTable[i].v = -FracMul(FracCos(angle), fixedRadius);
  352.  
  353.         angle += angleIncrement;
  354.     }
  355. }
  356.  
  357.  
  358. ///--------------------------------------------------------------------------------------
  359. //        ShipMoveProc
  360. ///--------------------------------------------------------------------------------------
  361.  
  362. void ShipMoveProc(
  363.     ShipSpritePtr shipSpriteP,
  364.     Point *spriteLoc)
  365. {
  366.     Point oldSpritePoint = *spriteLoc;
  367.  
  368.     SWWrapSpriteMoveProc((SpritePtr)shipSpriteP, spriteLoc);
  369.  
  370.     if (oldSpritePoint.h != spriteLoc->h || oldSpritePoint.v != spriteLoc->v)
  371.     {
  372.         shipSpriteP->shipHorizLoc = ff(spriteLoc->h);
  373.         shipSpriteP->shipVertLoc = ff(spriteLoc->v);
  374.     }
  375.  
  376.     if (KeyIsDown(kEscapeKey))                // hyperspace
  377.     {
  378.             // set position of ship
  379.         spriteLoc->h = GetRandom(shipSpriteP->shipSprite.moveBoundsRect.left + 10,
  380.                                             shipSpriteP->shipSprite.moveBoundsRect.right - 10);
  381.         spriteLoc->v = GetRandom(shipSpriteP->shipSprite.moveBoundsRect.top + 10,
  382.                                             shipSpriteP->shipSprite.moveBoundsRect.bottom - 10);
  383.  
  384.         shipSpriteP->shipHorizLoc = ff(spriteLoc->h);
  385.         shipSpriteP->shipVertLoc = ff(spriteLoc->v);
  386.  
  387.         shipSpriteP->shipVelocity.h = 0L;
  388.         shipSpriteP->shipVelocity.v = 0L;
  389.  
  390.         return;
  391.     }
  392.  
  393.         // check for thrust
  394.     if (KeyIsDown(kShiftKey))
  395.     {
  396.         shipSpriteP->shipVelocity.h += shipSpriteP->angularVelocityTable[shipSpriteP->shipSprite.curFrameIndex].h;
  397.         shipSpriteP->shipVelocity.v += shipSpriteP->angularVelocityTable[shipSpriteP->shipSprite.curFrameIndex].v;
  398.  
  399.             // enforce horizontal speed limit
  400.         if (shipSpriteP->shipVelocity.h > ff(kMaxShipVelocity))
  401.         {
  402.             shipSpriteP->shipVelocity.h = ff(kMaxShipVelocity);
  403.         }
  404.         else if (shipSpriteP->shipVelocity.h < ff(-kMaxShipVelocity))
  405.         {
  406.             shipSpriteP->shipVelocity.h = ff(-kMaxShipVelocity);
  407.         }
  408.  
  409.             // enforce vertical speed limit
  410.         if (shipSpriteP->shipVelocity.v > ff(kMaxShipVelocity))
  411.         {
  412.             shipSpriteP->shipVelocity.v = ff(kMaxShipVelocity);
  413.         }
  414.         else if (shipSpriteP->shipVelocity.v < ff(-kMaxShipVelocity))
  415.         {
  416.             shipSpriteP->shipVelocity.v = ff(-kMaxShipVelocity);
  417.         }
  418. /*
  419.             // is sound not already playing?
  420.         if (gShipSoundDone)
  421.         {
  422.                 // play thrust sound
  423.             if (SndPlay(shipSpriteP->shipSndChannelP, shipSpriteP->thrustSndH, true) == noErr)
  424.             {
  425.                 gShipSoundDone = false;
  426.  
  427.                 (void)SndDoCommand(shipSpriteP->shipSndChannelP, &shipSpriteP->shipSndCmd, true);
  428.             }
  429.         }
  430. */
  431.     }
  432.  
  433.         // apply velocity to current position
  434.     shipSpriteP->shipHorizLoc += shipSpriteP->shipVelocity.h;
  435.     shipSpriteP->shipVertLoc += shipSpriteP->shipVelocity.v;
  436.  
  437.         // set position of ship
  438.     spriteLoc->h = FixToShort(shipSpriteP->shipHorizLoc);
  439.     spriteLoc->v = FixToShort(shipSpriteP->shipVertLoc);
  440. }
  441.  
  442.  
  443. ///--------------------------------------------------------------------------------------
  444. //        FireAShot
  445. ///--------------------------------------------------------------------------------------
  446.  
  447. void FireAShot(
  448.     ShipSpritePtr shipSpriteP)
  449. {
  450.     register ShotSpritePtr shotSpriteP;
  451.  
  452.     shotSpriteP = shipSpriteP->shotSpriteArray[shipSpriteP->shotCounter];
  453.  
  454.     SWAddSprite(shipSpriteP->shotSpriteLayerP, (SpritePtr)shotSpriteP);
  455.     SWSetSpriteLocation((SpritePtr)shotSpriteP,
  456.                                 shipSpriteP->shipSprite.destFrameRect.left + kShotPosOffset,
  457.                                 shipSpriteP->shipSprite.destFrameRect.top + kShotPosOffset);
  458.  
  459.     shotSpriteP->shotLife = 0;
  460.     shotSpriteP->shotHorizLoc = shipSpriteP->shipHorizLoc + ff(kShotPosOffset);
  461.     shotSpriteP->shotVertLoc = shipSpriteP->shipVertLoc + ff(kShotPosOffset);
  462.     shotSpriteP->shotVelocity = shipSpriteP->shotVelocityTable[((SpritePtr)shipSpriteP)->curFrameIndex];
  463.  
  464.     shipSpriteP->shotCounter++;
  465.  
  466.     if (shipSpriteP->shotCounter == kNumberOfShotSprites)
  467.     {
  468.         shipSpriteP->shotCounter = 0;
  469.     }
  470.  
  471.         // play shot sound
  472.     //(void)SndPlay(shipSpriteP->shipSndChannelP, shipSpriteP->shotSndH, true);
  473. }
  474.  
  475.  
  476. ///--------------------------------------------------------------------------------------
  477. //        ShipFrameProc
  478. ///--------------------------------------------------------------------------------------
  479.  
  480. void ShipFrameProc(
  481.     ShipSpritePtr shipSpriteP,
  482.     FramePtr curFrameP,
  483.     long* curFrameIndex)
  484. {
  485. /*
  486.         // is the ship exploding?
  487.     if (srcSpriteP->curFrameIndex >= kFirstExplosionFrame)
  488.     {
  489.             // is the ship done exploding
  490.         if (srcSpriteP->curFrameIndex == kLastExplosionFrame)
  491.         {
  492.             *curFrameIndex = kFirstShipFrame;
  493.  
  494.                 // set position of ship
  495.             shipSpriteP->isAlive = false;
  496.         }
  497.         else
  498.         {
  499.             (*curFrameIndex)++;
  500.         }
  501.  
  502.         return;
  503.     }
  504. */
  505.  
  506.     if (KeyIsDown(kLeftArrowKey))                    // turn left
  507.     {
  508.             // rotate left
  509.         if (*curFrameIndex == kFirstShipFrame)
  510.         {
  511.             *curFrameIndex = kLastShipFrame;
  512.         }
  513.         else
  514.         {
  515.             (*curFrameIndex)--;
  516.         }
  517.     }
  518.     else if (KeyIsDown(kRightArrowKey))        // turn right
  519.     {
  520.             // rotate right
  521.         if (*curFrameIndex == kLastShipFrame)
  522.         {
  523.             *curFrameIndex = kFirstShipFrame;
  524.         }
  525.         else
  526.         {
  527.             (*curFrameIndex)++;
  528.         }
  529.     }
  530. }
  531.  
  532.  
  533. ///--------------------------------------------------------------------------------------
  534. //        ShipCollideProc
  535. ///--------------------------------------------------------------------------------------
  536.  
  537. void ShipCollideProc(
  538.     ShipSpritePtr shipSpriteP,
  539.     SpritePtr rockSpriteP,
  540.     Rect* sectRect)
  541. {
  542.     short newHorizLoc, newVertLoc;
  543.     Rect rgnRect = (**rockSpriteP->curFrameP->maskRgn).rgnBBox;
  544.  
  545.         // move the mask region to the new sprite location
  546.     OffsetRgn(rockSpriteP->curFrameP->maskRgn,
  547.                 (rockSpriteP->destFrameRect.left - rgnRect.left) +
  548.                 rockSpriteP->curFrameP->offsetPoint.h,
  549.                 (rockSpriteP->destFrameRect.top - rgnRect.top) +
  550.                 rockSpriteP->curFrameP->offsetPoint.v);
  551.  
  552.     rgnRect = (**shipSpriteP->shipSprite.curFrameP->maskRgn).rgnBBox;
  553.  
  554.         // move the mask region to the new sprite location
  555.     OffsetRgn(shipSpriteP->shipSprite.curFrameP->maskRgn,
  556.                 (shipSpriteP->shipSprite.destFrameRect.left - rgnRect.left) +
  557.                 shipSpriteP->shipSprite.curFrameP->offsetPoint.h,
  558.                 (shipSpriteP->shipSprite.destFrameRect.top - rgnRect.top) +
  559.                 shipSpriteP->shipSprite.curFrameP->offsetPoint.v);
  560.  
  561.     SectRgn(rockSpriteP->curFrameP->maskRgn, shipSpriteP->shipSprite.curFrameP->maskRgn, gWorkRgn);
  562.  
  563.     if (!EmptyRgn(gWorkRgn))
  564.     {
  565. /*
  566.         if (SndPlay(shipSpriteP->shipSndChannelP, shipSpriteP->explosionSndH, true) == noErr)
  567.         {
  568.             gShipSoundDone = false;
  569.     
  570.             (void)SndDoCommand(shipSpriteP->shipSndChannelP, &shipSpriteP->shipSndCmd, true);
  571.         }
  572. */
  573.         //SWSetSpriteFrame((SpritePtr)shipSpriteP, kFirstExplosionFrame);
  574.         //SWSetSpriteMoveDelta(shipSpriteP, 0, 0);
  575.  
  576.         newHorizLoc = shipSpriteP->shipSprite.moveBoundsRect.right / 2;
  577.         newVertLoc = shipSpriteP->shipSprite.moveBoundsRect.bottom / 2;
  578.  
  579.         shipSpriteP->shipHorizLoc = ff(newHorizLoc);
  580.         shipSpriteP->shipVertLoc = ff(newVertLoc);
  581.  
  582.         shipSpriteP->shipVelocity.h = 0L;
  583.         shipSpriteP->shipVelocity.v = 0L;
  584.  
  585.         SWMoveSprite((SpritePtr)shipSpriteP, newHorizLoc, newVertLoc);
  586.         SWSetSpriteVisible((SpritePtr)shipSpriteP, false);
  587.         SWSetSpriteMoveTime((SpritePtr)shipSpriteP, -1);
  588.  
  589.         shipSpriteP->isAlive = false;
  590.     }
  591. }
  592.  
  593.  
  594. ///--------------------------------------------------------------------------------------
  595. //        ShotMoveProc
  596. ///--------------------------------------------------------------------------------------
  597.  
  598. void ShotMoveProc(
  599.     ShotSpritePtr shotSpriteP,
  600.     Point *spriteLoc)
  601. {
  602.     if (!shotSpriteP->shotSprite.isVisible)
  603.     {
  604.         SWRemoveSprite(shotSpriteP->shipSpriteP->shotSpriteLayerP, (SpritePtr)shotSpriteP);
  605.         SWSetSpriteVisible((SpritePtr)shotSpriteP, true);
  606.     }
  607.     else
  608.     {
  609.         Point oldSpriteLoc = *spriteLoc;
  610.  
  611.         SWWrapSpriteMoveProc((SpritePtr)shotSpriteP, spriteLoc);
  612.  
  613.         if (spriteLoc->h != oldSpriteLoc.h || spriteLoc->v != oldSpriteLoc.v)
  614.         {
  615.             shotSpriteP->shotHorizLoc = ff(spriteLoc->h);
  616.             shotSpriteP->shotVertLoc = ff(spriteLoc->v);
  617.         }
  618.  
  619.         if (shotSpriteP->shotLife == kShotLifeExpectancy)
  620.         {
  621.             shotSpriteP->shotLife = 0L;
  622.  
  623.             SWSetSpriteVisible((SpritePtr)shotSpriteP, false);
  624.         }
  625.         else
  626.         {
  627.             shotSpriteP->shotLife++;
  628.  
  629.                 // apply velocity to current position
  630.             shotSpriteP->shotHorizLoc += shotSpriteP->shotVelocity.h;
  631.             shotSpriteP->shotVertLoc += shotSpriteP->shotVelocity.v;
  632.  
  633.                 // set position of shot
  634.             spriteLoc->h = FixToShort(shotSpriteP->shotHorizLoc);
  635.             spriteLoc->v = FixToShort(shotSpriteP->shotVertLoc);
  636.         }
  637.     }
  638. }
  639.  
  640.  
  641. ///--------------------------------------------------------------------------------------
  642. //        ShipSoundCallBack
  643. ///--------------------------------------------------------------------------------------
  644.  
  645. pascal void ShipSoundCallBack(
  646.     SndChannelPtr sndChannelP,
  647.     SndCommand *sndCmdP)
  648. {
  649.         // a pointer to gSoundDone is in param2
  650.     *(Boolean*)sndCmdP->param2 = true;
  651. }
  652.  
  653.  
  654.